﻿using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;

namespace TSharp.Core.Aop.Handler
{
    /// <summary>
    /// 
    /// <para>2010/9/27</para>
    /// 	<para>TANGJINGBO</para>
    /// 	<author>tangjingbo</author>
    /// </summary>
    public class PermissionsHandler : ICallHandler
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="PermissionsHandler"/> class.
        /// </summary>
        /// <param name="container">The container.</param>
        public PermissionsHandler(IUnityContainer container)
            : this()
        {
            Container = container;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="PermissionsHandler"/> class.
        /// </summary>
        public PermissionsHandler()
        {
            Order = 0;
        }

        #region ICallHandler 成员

        /// <summary>
        /// Implement this method to execute your handler processing.
        /// </summary>
        /// <param name="input">Inputs to the current call to the target.</param>
        /// <param name="getNext">Delegate to execute to get the next delegate in the handler
        /// chain.</param>
        /// <returns>Return value from the target.</returns>
        public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
        {
            return getNext()(input, getNext);
        }

        /// <summary>
        /// Order in which the handler will be executed
        /// </summary>
        /// <value></value>
        public int Order { get; set; }

        #endregion

        /// <summary>
        /// Gets or sets the container.
        /// </summary>
        /// <value>The container.</value>
        public IUnityContainer Container { get; set; }
    }
}